package com.harry.controller;

import com.harry.pojo.Doctor;
import com.harry.pojo.RegisterRecord;
import com.harry.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.harry.mapper.UserMapper;

import javax.websocket.server.PathParam;
import java.sql.Timestamp;
import java.util.List;

@RestController
@RequestMapping("/patient")
public class UserController
{
    @Autowired
    private UserService userService;

    @GetMapping("/login/{open_id}")
    public String login(@PathVariable String open_id)
    {
        return userService.login(open_id);
    }

    @GetMapping("/getDoctors")
    public List<Doctor> getDoctors()
    {
        return userService.getDoctors();
    }

    @GetMapping("/register/{open_id}/{doctorId}/{startTime}")
    public String register(@PathVariable int doctorId, @PathVariable String open_id, @PathVariable String startTime)
    {
        startTime = startTime.split("%20")[0];
        System.out.println(startTime);
        Timestamp start_time = Timestamp.valueOf(startTime);
        return userService.register(doctorId, open_id, start_time);
    }

    @GetMapping("/payment/{open_id}")
    public String payment(@PathVariable String open_id)
    {
        return userService.payment(open_id);
    }

    @GetMapping("/getMedicine/{open_id}")
    public List<String> getMedicine(@PathVariable String open_id)
    {
        return userService.getMedicine(open_id);
    }

    @GetMapping("/getNowStage/{open_id}")
    public int getNowStage(@PathVariable String open_id)
    {
        return userService.getNowStage(open_id);
    }

    @GetMapping("getRegisterRecord/{open_id}")
    public List<RegisterRecord> getRegisterRecord(@PathVariable String open_id)
    {
        return userService.getRegisterRecord(open_id);
    }
}
